package com.wxp.demo06.application.room.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;


import com.wxp.demo06.application.room.entity.BookInfoEntity;

import java.util.List;

/**
 * 图书数据层接口
 */
@Dao
public interface BookDao {

    @Insert
    void insert(BookInfoEntity... book);

    @Delete
    void delete(BookInfoEntity... book);

    /**
     * 删除所有书籍信息
     */
    @Query("DELETE FROM book_info")
    void deleteAll();

    @Update
    int update(BookInfoEntity... book);

    /**
     * 加载所有书籍信息
     *
     * @return 所有书籍信息
     */
    @Query("SELECT * FROM book_info")
    List<BookInfoEntity> queryAll();

    /**
     * 根据名字加载书籍
     *
     * @param name 图书名称
     * @return 书籍信息
     */
    @Query("SELECT * FROM book_info WHERE name = :name ORDER BY id DESC limit 1")
    BookInfoEntity queryByName(String name);
}
